<template>
  <card-layout title="储量统计" class="chart" bg="2">
    <div class="card-container">
      <div class="chart-container">
        <div style="width: 100%; height: 100%" ref="chartRef"></div>
        <div class="chart-label">
          <div class="percent">29.8%</div>
          <div class="txt">储量利用率</div>
        </div>
      </div>
      <div class="stat-group">
        <div class="item">
          <div class="label">总储量</div>
          <div class="value">583234</div>
        </div>
        <div class="item">
          <div class="label">已开采</div>
          <div class="value">18781</div>
        </div>
        <div class="item">
          <div class="label">剩余储量</div>
          <div class="value">150004</div>
        </div>
      </div>
    </div>
  </card-layout>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from "vue";
import useChart from "@/hooks/useCharts.js";
const chartRef = ref(null);
let { chartInstance } = useChart(chartRef);

// 初始化图表
const initChart = () => {
  const option = {
    tooltip: {
      show: false,
    },
    legend: {
      show: false,
    },
    series: [
      {
        name: "Access From",
        type: "pie",
        radius: ["65%", "90%"],
        avoidLabelOverlap: false,
        label: {
          show: false,
          position: "center",
        },
        labelLine: {
          show: false,
        },
        data: [
          {
            value: 28.2,
            name: "已挖",
            itemStyle: {
              color: "#ffc107",
              borderRadius: "8px",
            },
          },
          {
            value: 71.8,
            name: "未挖",
            itemStyle: {
              color: "#9e9e9e9e",
              borderRadius: "8px",
            },
          },
        ],
      },
    ],
  };
  chartInstance.value.setOption(option);
};

onMounted(() => {
  initChart();
});
</script>

<style lang="scss" scoped>
.chart {
  box-sizing: border-box;
  flex: 0.6;

  .card-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    padding: 8px;
  }

  .chart-container {
    flex: 1;
    width: 100%;
    position: relative;

    .chart-label {
      user-select: none;
      position: absolute;
      pointer-events: none;
      top: 0px;
      left: 0px;
      z-index: 1;
      height: 100%;
      width: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;

      .percent {
        font-size: 26px;
        color: #fff;
      }

      .txt {
        color: #dedede;
        font-size: 14px;
      }
    }
  }

  .reserves-info {
    display: flex;
    justify-content: space-around;
    padding: 10px 0;

    .info-item {
      text-align: center;

      .label {
        color: #bbcfff;
        font-size: 14px;
        margin-bottom: 5px;
      }

      .value {
        color: #1fc6ff;
        font-size: 28px;
        font-family: "UnidreamLED";
      }
    }
  }
}
</style>
